/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import javax.swing.JOptionPane;
import model.Game;
import model.LevelSpecification;

/**
 *
 * @author Misja
 */
public class GameFrame extends javax.swing.JFrame {

    private Game game;

    /**
     * Creates new form GameFrame
     */
    public GameFrame(LevelSpecification levelSpecification) {
        initComponents();
        this.setTitle("Level: " + levelSpecification.getName() + " Difficulty: " + levelSpecification.getDifficulty().toString().toLowerCase());
        this.game = new Game(pnlField, this);
        this.game.initLevel(levelSpecification);
    }

    private GameFrame() {
    }

    public void messageDialog(String message) {
        JOptionPane.showMessageDialog(rootPane, message);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnStart = new javax.swing.JButton();
        btnStop = new javax.swing.JButton();
        btnPauze = new javax.swing.JButton();
        pnlField = new view.FieldPanel();
        mbMain = new javax.swing.JMenuBar();
        mNavigation = new javax.swing.JMenu();
        miLevelSelection = new javax.swing.JMenuItem();
        miLevelManager = new javax.swing.JMenuItem();
        miHome = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Game");
        setLocationByPlatform(true);
        setResizable(false);

        btnStart.setText("Start");
        btnStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStartActionPerformed(evt);
            }
        });

        btnStop.setText("Stop");
        btnStop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStopActionPerformed(evt);
            }
        });

        btnPauze.setText("Pauze");
        btnPauze.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPauzeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlFieldLayout = new javax.swing.GroupLayout(pnlField);
        pnlField.setLayout(pnlFieldLayout);
        pnlFieldLayout.setHorizontalGroup(
            pnlFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 598, Short.MAX_VALUE)
        );
        pnlFieldLayout.setVerticalGroup(
            pnlFieldLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 598, Short.MAX_VALUE)
        );

        mNavigation.setText("Navigate");

        miLevelSelection.setText("Level Selection");
        miLevelSelection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miLevelSelectionActionPerformed(evt);
            }
        });
        mNavigation.add(miLevelSelection);

        miLevelManager.setText("Level Manager");
        miLevelManager.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miLevelManagerActionPerformed(evt);
            }
        });
        mNavigation.add(miLevelManager);

        miHome.setText("Home");
        miHome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miHomeActionPerformed(evt);
            }
        });
        mNavigation.add(miHome);

        mbMain.add(mNavigation);

        setJMenuBar(mbMain);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnStart, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnStop, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnPauze))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnStart)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnStop)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnPauze)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed
        this.game.start();
        this.requestFocus();
    }//GEN-LAST:event_btnStartActionPerformed

    private void btnStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopActionPerformed
        this.game.stop();
        new LevelManagerFrame().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_btnStopActionPerformed

    private void btnPauzeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPauzeActionPerformed
        this.game.stop();
        Object[] options = {"Hervatten", "Stoppen"};
        int returnValue = JOptionPane.showOptionDialog(rootPane, "Wilt u het spel hervatten of stoppen?", "Pauze", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
        if (returnValue == 0) {
            this.game.start();
            this.requestFocus();
        } else {
            new LevelManagerFrame().setVisible(true);
            this.dispose();
        }


    }//GEN-LAST:event_btnPauzeActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void miHomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miHomeActionPerformed
        new HomeFrame().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_miHomeActionPerformed

    private void miLevelManagerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLevelManagerActionPerformed
        new LevelManagerFrame().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_miLevelManagerActionPerformed

    private void miLevelSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLevelSelectionActionPerformed
        new LevelSelectionFrame().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_miLevelSelectionActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GameFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnPauze;
    private javax.swing.JButton btnStart;
    private javax.swing.JButton btnStop;
    private javax.swing.JMenu mNavigation;
    private javax.swing.JMenuBar mbMain;
    private javax.swing.JMenuItem miHome;
    private javax.swing.JMenuItem miLevelManager;
    private javax.swing.JMenuItem miLevelSelection;
    private view.FieldPanel pnlField;
    // End of variables declaration//GEN-END:variables
}
